import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/index/Home.vue'
import Hb from '../views/HB/Hb.vue'
import MyCenterIndex from '../views/MyCenter/MyCenterIndex.vue'
import MyCenter from '../views/MyCenter/MyCenter.vue'
import MyAcceptEs from '../views/MyCenter/MyAcceptEs.vue'
import MyAcceptHb from '../views/MyCenter/MyAcceptHb.vue'
import MyEs from '../views/MyCenter/MyEs.vue'
import MyHb from '../views/MyCenter/MyHb.vue'
import MyMoney from '../views/MyCenter/MyMoney.vue'
import UpdateUserInfo from '../views/MyCenter/UpdateUserInfo.vue'
import SerchBegin from '../views/serch/SerchBegin.vue'
import Login from '../views/auth/Login.vue'
import SignUp from '../views/auth/SignUp.vue'
import Bottom from '../components/Bottom.vue'
const routes = [
  {
    path: '/',
    name: 'Bottom',
    component: Bottom,
    children :[
      {
        path: '/',
        name: 'Home',
        component: Home
      },
      {
        path: '/hb',
        name: 'Hb',
        component: Hb
      },
      {
        path: '/center',
        name: 'MyCenterIndex',
        component: MyCenterIndex,
        children: [
          {
            path: '/center',
            name: 'Center',
            component: MyCenter,
          },
          {
            path: '/center/myacceptes',
            name: 'MyAcceptEs',
            component: MyAcceptEs
          },
          {
            path: '/center/myaccepthb',
            name: 'MyAcceptHb',
            component: MyAcceptHb
          },
          {
            path: '/center/myes',
            name: 'MyEs',
            component: MyEs
          },
          {
            path: '/center/myhb',
            name: 'MyHb',
            component: MyHb
          },
          {
            path: '/center/mymoney',
            name: 'MyMoney',
            component: MyMoney
          },
          {
            path: '/center/updateuserinfo',
            name: 'UpdateUserInfo',
            component: UpdateUserInfo
          },
        ]
      },
      {
        path: '/serch',
        name: 'SerchBegin',
        component: SerchBegin
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path:'/sign',
    name:'Sign',
    component:SignUp
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to,from,next) => {
  if(to.name === 'Center' && (localStorage.isLogin === '0'|| !localStorage.isLogin)) next({ name: 'Login' })
  else next()
})

export default router
